package cn.tedu.supermarket.types.service.impl;

import cn.tedu.supermarket.types.mapper.TypesMapper;
import cn.tedu.supermarket.types.pojo.dto.TypesQuery;
import cn.tedu.supermarket.types.pojo.dto.TypesSaveParam;
import cn.tedu.supermarket.types.pojo.entity.Types;
import cn.tedu.supermarket.types.pojo.vo.TypesVO;
import cn.tedu.supermarket.types.service.TypesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Slf4j
@Service
public class TypesServiceImpl implements TypesService {
    @Autowired
    private TypesMapper typesMapper;

    @Override
    public List<TypesVO> selectTypes(TypesQuery typesQuery) {
        log.debug("分类查询业务,参数:{}", typesQuery);
        List<TypesVO> list = typesMapper.selectTypes(typesQuery);
        return list;
    }

    @Override
    public void saveTypes(TypesSaveParam typesVO) {
        log.debug("保存业务,参数:{}", typesVO);
        Types types = new Types();
        BeanUtils.copyProperties(typesVO, types);
        if (typesVO.getId() == null){
            typesMapper.insertTypes(types);
        }else {
            typesMapper.updateTypes(types);
        }
    }

    @Override
    public void deleteTypes(Long typeId) {
        log.debug("删除业务,参数:{}", typeId);
        typesMapper.deleteTypes(typeId);
    }
}
